/**   
* @Title: HttpUtils.java 
* @Package com.snbc.transfer.common.utils 
* @Description: TODO(用一句话描述该文件做什么) 
* @author ligang  
* @date 2016年4月16日 下午3:00:40 
* @version V1.0   
*/
package com.snbc.util;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

/** 
 * @ClassName: HttpUtils 
 * @Description: 访问http协议工具类，负责 get,post 以及文件下载等功能
 * @author Ligang
 * @date 2016年4月16日 下午3:00:40 
 *  
 */
public class HttpUtils {
	private static final Logger logger = LoggerFactory.getLogger(HttpUtils.class);
	/**
	 * 通过 http get方法获取相应结果
	* @Title: httpGet 
	* @Description: T通过 http get方法获取相应结果
	* @param url  访问地址
	* @return  JSONObject  json对象
	* @throws ParseException
	* @throws IOException
	*
	 */
	public static String httpGet(String url) {
		HttpClient httpclient = new DefaultHttpClient();
		HttpGet get=new HttpGet(url);
		HttpResponse response=null;
		String body=null;
		try {
			response = httpclient.execute(get);
			HttpEntity entity=response.getEntity();
			body = EntityUtils.toString(entity);
		} catch (ClientProtocolException e) {
			logger.error("http获取:"+url+" 失败"+e.getMessage());
			e.printStackTrace();
		} catch (IOException e) {
			logger.error("http获取:"+url+" 失败"+e.getMessage());
			e.printStackTrace();
		} catch (ParseException e) {
			logger.error("http获取:"+url+" 解析内容失败"+e.getMessage());
		}
		if (body==null)
			return null;
		return body;
	}
	
	

	



	public static String getIP() throws UnknownHostException {
		InetAddress inetAddress = InetAddress.getLocalHost();
        return inetAddress.getHostAddress();
	}
}
